//
// Created by dwx on 2024/4/19.
//
#include "main.h"
#include "can.h"
#include "dma.h"
#include "usart.h"
#include "usb_device.h"
#include "gpio.h"
#include "FreeRTOS.h"
#include "task.h"

//ÈÎÎñÓÅÏÈ¼¶
#define START_TASK_PRIO		1
//ÈÎÎñ¶ÑÕ»´óÐ¡
#define START_STK_SIZE 		128
//ÈÎÎñ¾ä±ú
TaskHandle_t StartTask_Handler;
//ÈÎÎñº¯Êý
void start_task(void *pvParameters);

//ÈÎÎñÓÅÏÈ¼¶
#define LED0_TASK_PRIO		2
//ÈÎÎñ¶ÑÕ»´óÐ¡
#define LED0_STK_SIZE 		50
//ÈÎÎñ¾ä±ú
TaskHandle_t LED0Task_Handler;
//ÈÎÎñº¯Êý
void led0_task(void *pvParameters);

//ÈÎÎñÓÅÏÈ¼¶
#define LED1_TASK_PRIO		3
//ÈÎÎñ¶ÑÕ»´óÐ¡
#define LED1_STK_SIZE 		50
//ÈÎÎñ¾ä±ú
TaskHandle_t LED1Task_Handler;
//ÈÎÎñº¯Êý
void led1_task(void *pvParameters);



void led0_task(void *pvParameters)
{

    while(1)
    {

        vTaskDelay(500);
    }
}

//LED1ÈÎÎñº¯Êý
void led1_task(void *pvParameters)
{
    while(1)
    {

        vTaskDelay(200);

    }
}



void start_task(void *pvParameters)
{
    taskENTER_CRITICAL();           //½øÈëÁÙ½çÇø
    //´´½¨LED0ÈÎÎñ
    xTaskCreate((TaskFunction_t )led0_task,
                (const char*    )"led0_task",
                (uint16_t       )LED0_STK_SIZE,
                (void*          )NULL,
                (UBaseType_t    )LED0_TASK_PRIO,
                (TaskHandle_t*  )&LED0Task_Handler);
    //´´½¨LED1ÈÎÎñ
    xTaskCreate((TaskFunction_t )led1_task,
                (const char*    )"led1_task",
                (uint16_t       )LED1_STK_SIZE,
                (void*          )NULL,
                (UBaseType_t    )LED1_TASK_PRIO,
                (TaskHandle_t*  )&LED1Task_Handler);
    vTaskDelete(StartTask_Handler); //É¾³ý¿ªÊ¼ÈÎÎñ
    taskEXIT_CRITICAL();            //ÍË³öÁÙ½çÇø
}


void Main(void){
    xTaskCreate((TaskFunction_t )start_task,            //ÈÎÎñº¯Êý
                (const char*    )"start_task",          //ÈÎÎñÃû³Æ
                (uint16_t       )START_STK_SIZE,        //ÈÎÎñ¶ÑÕ»´óÐ¡
                (void*          )NULL,                  //´«µÝ¸øÈÎÎñº¯ÊýµÄ²ÎÊý
                (UBaseType_t    )START_TASK_PRIO,       //ÈÎÎñÓÅÏÈ¼¶
                (TaskHandle_t*  )&StartTask_Handler);   //ÈÎÎñ¾ä±ú
    vTaskStartScheduler();          //¿ªÆôÈÎÎñµ÷¶È

}
